package com.qingsong.controller;

import com.mybatisflex.core.paginate.Page;
import com.qingsong.dto.BannerInsertDTO;
import com.qingsong.dto.BannerPageDTO;
import com.qingsong.dto.BannerUpdateDTO;
import com.qingsong.entity.Banner;
import com.qingsong.result.Result;
import com.qingsong.vo.BannerSimpleListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.qingsong.service.BannerService;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 横幅表 控制层。
 *
 * @author qingsong
 * @since 2024-12-22
 */
@Tag(name = "横幅")
@RestController
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @Operation(summary = "新增-单条", description = "新增一条轮播图记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody BannerInsertDTO dto) {
        return bannerService.insert(dto);
    }

    @Operation(summary = "查询-前N条记录", description = "查询-前N条记录")
    @GetMapping("top/{n}")
    public List<Banner> top(@PathVariable("n") Long n) {
        return bannerService.top(n);
    }

    @Operation(summary = "查询-单条", description = "按主键查询一条轮播图记录")
    @GetMapping("select/{id}")
    public Banner select(@PathVariable("id") Long id) {
        return bannerService.select(id);
    }
    @Operation(summary = "查询-分页", description = "分页查询轮播图记录")
    @GetMapping("page")
    public Page<Banner> page(@Validated BannerPageDTO dto) {
        return bannerService.page(dto);
    }

    @Operation(summary = "查询-全部", description = "查询全部轮播图记录")
    @GetMapping("list")
    public List<Banner> list() {
        return bannerService.list();
    }

    @Operation(summary = "查询 - 简单列表", description = "查询-简单列表")
    @GetMapping("simpleList")
    public List<BannerSimpleListVO> simpleList() {
        return bannerService.simpleList();
    }
    @Operation(summary = "修改 - 横幅图片", description = "按主键修改横幅图片")
    @PostMapping("/uploadBanner/{id}")
    public Result<String> uploadBanner(@PathVariable("id") Long id, @RequestParam("bannerFile") MultipartFile bannerFile) {
        return new Result<>(bannerService.uploadBanner(bannerFile, id));
    }
    @Operation(summary = "修改-单条", description = "按主键修改一条轮播图记录")
    @PutMapping("update")
    public boolean update(@RequestBody BannerUpdateDTO dto) {
        return bannerService.update(dto);
    }

    @Operation(summary = "删除-单条", description = "按主键删除一条轮播图记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return bannerService.delete(id);
    }

    @Operation(summary = "删除-批量", description = "按主键批量删除轮播图记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return bannerService.deleteBatch(ids);
    }


}
